package cn.yuan.xiaoyu.caipumodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.yuan.xiaoyu.R;
import cn.yuan.xiaoyu.caipumodule.activity.CaiPuActivity;
import cn.yuan.xiaoyu.caipumodule.bean.CaiPuListBean;
import cn.yuan.xiaoyu.commonmodule.utils.ListUtils;

/**
 * Created by yukuoyuan on 2017/2/28.
 * 这是一个菜谱列表的适配器
 */

public class CaipuListAdapter extends RecyclerView.Adapter<CaipuListAdapter.MyHolder> {
    List<CaiPuListBean.ResultBean.DataBean> listBeen;
    CaiPuActivity caiPuActivity;

    public CaipuListAdapter(List<CaiPuListBean.ResultBean.DataBean> listBeen, CaiPuActivity caiPuActivity) {
        this.listBeen = listBeen;
        this.caiPuActivity = caiPuActivity;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_caipu_list, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        Glide.with(caiPuActivity).load(listBeen.get(position).albums.get(0))
                .centerCrop()
                .into(holder.iv_item_caipu_list);
//        holder.iv_item_caipu_list.setText(listBeen.get(position).name);
    }

    @Override
    public int getItemCount() {
        if (ListUtils.isEmpty(listBeen)) {
            return 0;
        }
        return listBeen.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        private final ImageView iv_item_caipu_list;

        public MyHolder(View itemView) {
            super(itemView);
            iv_item_caipu_list = (ImageView) itemView.findViewById(R.id.iv_item_caipu_list);
        }
    }
}
